package com.tanglongan.designPattern.dp10_proxy.demo01;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class JdkMeiPo implements InvocationHandler {

    private IPerson target;

    public IPerson getPerson(IPerson target) {
        this.target = target;
        Class<?> clazz = target.getClass();
        return (IPerson) Proxy.newProxyInstance(clazz.getClassLoader(), clazz.getInterfaces(), this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        before();
        Object result = method.invoke(this.target, args);
        after();
        return result;
    }


    public void before() {
        System.out.println("我是媒婆，已经开始收集你的需求了，开始物色。");

    }

    public void after() {
        System.out.println("双方同意，开始交往。");
    }

}
